<!DOCTYPE html>
<html lang="zh-CN">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>档案管理 -首页</title>
<!--[if lt IE 9]>
<script src="libs/html5shiv.min.js"></script>
<script src="libs/respond.min.js"></script>
<![endif]-->
<script src="libs/jquery-1.12.1.min.js"></script>
<link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
<script src="libs/handlebars.min.js"></script>
<script src="libs/js.cookie-2.1.0.min.js"></script>
<script src="libs/getQueryString.js"></script>
<script src="libs/jquery.backstretch.min.js"></script>
<script src="libs/md5.min.js"></script>
<script src="libs/jquery.backstretch.min.js"></script>
</head> 
<body>
	<div class="container">
		<div class="row">
			<div class="col-md-1 page-header">
				<button id="logout" class="btn btn-primary btn-block">退出</button>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="page-header">
				<h2 class="text-center">
					档案管理<br /> <small>首页</small>
				</h2>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-md-6">
				<ul class="nav nav-pills pull-right">
					<li><a href="#">用户：<span id="text1"></span></a></li>
					<li class="active"><a href="#">首页</a></li>
					<li><a href="add.html">添加</a></li>

					<li><a href="count.html">统计</a></li>

					<li><a href="query.html">查询</a></li>
				</ul>
			</div>
			<div class="  col-md-offset-9">
				
				<div class="row">
					<div class="col-lg-11">
    					<div class="input-group">
     		 			   <input type="text" class="form-control"  id="archive" placeholder="请输入档案号或身份证号码"  >
     		  			   <span class="input-group-btn">
              			   <button class="btn btn-default" id="queryNumber" type="button">Go!</button>
                		   </span>
						</div>
					</div>	
				</div>
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">
			<hr />
		</div>
	</div>
	<div class="container">
	<div class="col-md-10 col-md-offset-1">
		<div class="panel panel-default">
			<div class="panel-heading"><p class="text-primary">当前用户最近浏览的四份档案</p></div>
			<div class="panel-body" id="list1"></div>
		</div>
	</div>

	<div class="col-md-10 col-md-offset-1">
		<div class="panel panel-default">
			<div class="panel-heading"><p class="text-primary">当前用户最近添加的四份档案</p></div>
			<div class="panel-body" id="list2"></div>
		</div>
	</div>
	</div>
	<script type="text/javascript">
		$(function() {

			$.backstretch("photo/qingting.jpg");
			$('#logout').click(function() {
				$.post('logout.action', {}, function(res, status) {
					if ('OK' == res) {
						alert('退出成功');  
						window.location.href = 'login.html';
					}
				});
			});
			$.getJSON('querynickname.action', function(res) {
				console.log(res);
				$('#text1').text(res[0].nickname);
			});

			$('#queryNumber').click(function() {
				$.post('queryNumber.action', {
					archiveId : $('#archive').val()
				}, function(res, status) {
					if ('ERR1' == res) {
						alert('未找到要查询的档案');
					} else if ('ERR2' == res) {
						alert('请输入正确的数据');
					} else {
						console.log(res);
						window.location.href = 'update.html?id=' + res;
					}
				})
			});
			
			$.getJSON('queryBrowse.action', function(res) {
				console.log(res);
				var data = {
					'item' : res
				};
				var t = Handlebars.compile($('#template').html());
				$('#list1').html(t(data));

			});
			$.getJSON('queryRecentlyAdd.action', function(res) {
				console.log(res);
				//res存在 json里  再把res存在item（json）里面  
				var data = {
					'item' : res
				};
				//调用Handlebars里面compile的这个方法，把 template 显示出来
				var t = Handlebars.compile($('#template').html());
				//必须需要 这样的形式 ：[{"fm":"300"},{"fm":"400"}]  才能显示出来 
				$('#list2').html(t(data));
			});

		});
	</script>
	<script id="template" type="text/x-handlebars-template">
	{{#each item}}
		<div class="panel panel-default col-md-3">
			<div class="panel-body">
				<dl>
					<dt>档案号</dt><dd>{{archive_id}}</dd>
					<dt>身份证号码</dt><dd>{{identity}}</dd>
					<dt>姓名</dt><dd>{{name}}</dd>
					<dt>性别</dt><dd>{{gender}}</dd>
        			<dt>职称</dt><dd>{{title}}</dd>
				</dl>
			</div>
		</div>
	{{/each}}

	</script>
</body>
</html>